#ifndef WIDGET_H
#define WIDGET_H

#include <QWidget>
#include <QMainWindow>
#include <QCamera>
#include <QCameraViewfinder>
#include <QCameraImageCapture>
#include <QCameraInfo>
#include <QFileDialog>
#include <QDialogButtonBox>
#include <QMessageBox>
#include <QHBoxLayout>
#include <QLabel>
#include <functional>
#include <QPushButton>
#include "videotool.h"
#include <iostream>
#include <fstream>
#include <string>

namespace Ui {
class Widget;
}

// 当前处于那个界面
enum whichUi{U1, U2, U3};

// 方向
enum DIRECT{
    UP=1,
    DOWN=2,
    FORWARD=3,
    BACK=4,
    LEFT=5,
    RIGHT=6,
    UPFORWARD,
    UPBACK,
    UPLEFT,
    UPRIGHT,
    DOWNFORWARD,
    DOWNBACK,
    DOWNLEFT,
    DOWNRIGHT,
    ORIGIN
};

// 手/自动
enum S1{AUTO, MANUAL};
// 是否到位
enum S2{PLACED, NOTPLACED};
// 是否启动
enum S3{START, STOP};
// 是否拧松
enum S4{LOOSE, NOTLOOSE};
// 外部
enum S5{P1, P2, P3};

class Widget : public QWidget
{
    Q_OBJECT

public:
    explicit Widget(QWidget *parent = 0);
    void initCamera();
    ~Widget();
    // 获取帧
    void grabCameraFrame(const QVideoFrame& buffer);
    
    void switchPage(whichUi which);
    
    void UIsetText(QString str_1, QString str_2);
    void UIsetText_top(QString str);
    void UIsetText_centre(QString str);

    QImage video_stream_push(QImage img);
    QImage video_stream_push_axisline(QImage img);

    // // 消息弹窗
    // void initInfoBox();
    // void clickInfoBoxYes();
    // void clickInfoBoxNo();

public:
    // QMessageBox* infoBox;
private:
    Ui::Widget *ui;
    QCamera *camera;
    myvideosurface* filter;
    

    // 消息弹窗 确定按钮
    QPushButton* yesBtn;
    QPushButton* noBtn;

    // 按钮常规样式
    const QString buttonTextBasicStyle = "\nbackground:rgb(190, 230, 255);\nfont: 32pt 'Adobe 黑体 Std R';";

    QList<QCameraInfo> m_camera;

    //目标角点
    std::vector<double> pointxy = {263.146240234375, 89.83887481689453, 243.709716796875, 92.89017486572266, 246.978759765625, 112.07119750976562, 266.4444580078125, 109.2481460571289, };
    double x[4] = {pointxy[0], pointxy[2], pointxy[4], pointxy[6]};
    double y[4] = {pointxy[1], pointxy[3], pointxy[5], pointxy[7]};

public:
    // 所有涉及到的状态量,随着外部改变
    whichUi which = U2;
    DIRECT direct = LEFT; // 转向
//    S1 s1 = AUTO;
//    S2 s2 = PLACED;
//    S3 s3 = START;
//    S4 s4 = LOOSE;
//    S5 s5 = P1;

    opencamera* filterViewFinder;

    // 用于处理帧的函数对象，初始为空，需要处理帧时更改即可
    std::function<QImage(QImage)> functor = nullptr;

    QImage img;
    QImage image_usbcam;

    int sleep_clock = 0;
    int view_is_simulation = 0;

    double apriltags_realtimepaint[32] = {0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};
};

#endif // WIDGET_H
